/* ======================================================= */
/**
 * File   : ToolBar.java
 * Date   : 3 mars 2010 at 11:51:58
 */
/* ======================================================= */
package fr.isima.isipaint.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import fr.isima.isipaint.tools.Action;
import fr.isima.isipaint.tools.ToolBox;

/* ======================================================= */
/**
 * 
 * @author Daniel
 * 
 */
/* ======================================================= */
public class ToolBar extends JPanel {

	/** Serial number */
	private static final long serialVersionUID = 1L;

	/** The buttons tool map */
	private Map<JButton, Action> buttons = new HashMap<JButton, Action>();

	/** The width of one button */
	private static final int BUTTON_WIDTH = 25;

	/** The height of one button */
	private static final int BUTTON_HEIGHT = 25;

	/** The marge between icons*/
	private static final int MARGE = 2;

	/** The tools set */
	private ToolBox tools;

	/**
	 * Default Constructor
	 */
	public ToolBar(ToolBox toolBox) {
		this.tools = toolBox;
		setBorder(BorderFactory.createLineBorder(Color.black));
		setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

		/* To store the mapping between buttons and actions */
		for (Action t : tools.getTools()) {
			JButton button = new JButton();
			if (t.isEnableIcon() && t.getIcon() != null) {
				button.setIcon(t.getIcon());
			} else {
				button.setText(t.getName());
			}
			button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
			buttons.put(button, t);
			
			for (Entry<JButton, Action> entry : buttons.entrySet()) {
				add(entry.getKey());
				add(Box.createRigidArea(new Dimension(MARGE, 0)));
			}
		}
	}

}
